package com.zj.study;

import org.bouncycastle.crypto.digests.SM3Digest;
import org.bouncycastle.util.encoders.Hex;

/**
 * @author 赵赳
 * @since 2021/9/27 9:30
 */
public class SM3test {

  public static void main(String[] args) {
    System.out.println(generateSM3HASH("123456"));

  }

  /**
   * SM3 摘要计算
   *
   * @param src 加密字符串
   * @return 密文
   */
  public static String generateSM3HASH(String src) {
    byte[] md = new byte[32];
    byte[] msg1 = src.getBytes();
    SM3Digest sm3 = new SM3Digest();
    sm3.update(msg1, 0, msg1.length);
    sm3.doFinal(md, 0);
    String s = new String(Hex.encode(md));
    return s.toUpperCase();
  }

}
